﻿using MDIDemo.Model;
using MDIDemo.PublicClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevMy.Vou
{
    public partial class Form_ResultCal : Form_BaseDialog
    {
        public Form_ResultCal()
        {
            InitializeComponent();
        }
        public string BatchId;
        public bool IsAuto = false;
        public void Ini()
        {
            base.SetComponent();
            this.Text = string.Format("批次号【{0}】---计算结果", BatchId);
            this.labelControl6.Text = BatchId;
            List<Class_GridColumnModel> class_GridColumnModels = new List<Class_GridColumnModel>();
            class_GridColumnModels = base.class_SQLiteOperator.GetGridColumnList(null);
            base.gridC.SetGridC(this.gridControl1, this.gridView1, "分组区", class_GridColumnModels);
            if (base.id != null)
                this.labelControl6.Text = BatchId;
            Display(BatchId);
        }
        /// <summary>
        /// 窗体状态
        /// </summary>
        /// <param name="WinType">-1：查看，0：修改，1：增加</param>
        public void SetWinType(int WinType)
        {
            base.WinType = WinType;
        }

        private void Display(string id)
        {
            if (id != null && id.Split('_').Length == 2)
            {
                Class_PublicMethod class_PublicMethod = new Class_PublicMethod();
                Class_DataBaseConDefault class_DataBaseConDefault = new Class_DataBaseConDefault();
                class_DataBaseConDefault = class_PublicMethod.FromXmlToDefaultValueObject<Class_DataBaseConDefault>("DataBaseDefaultValues");
                base.class_MySqlDataBase = new Class_MySqlDataBase(class_DataBaseConDefault.dataSourceUrl
                    , "yantu"
                    , class_DataBaseConDefault.dataSourceUserName
                    , class_DataBaseConDefault.dataSourcePassWord
                    , class_DataBaseConDefault.Port);

                string Separattion = string.Format("_{0}", id.Split('_')[0]);
                //if (IsAuto)
                //    id = id.Split('_')[1];
                string Sql = string.Format(@"SELECT sortNo as 序号
                    ,正应力
                    ,局部坐标系应力
                    ,大地坐标系应力
                    ,li1
                    ,pqθ
                    ,主应力123
                    ,li2
                    ,mi2
                    ,ni2
                    ,主应力倾角β
                    ,主应力方位角α
                    ,channelNo as 通道号
                    FROM output_data{1}
                    WHERE batchId = '{0}'
                    ORDER BY sortNo", id, Separattion);
                DataTable dataTable = base.class_MySqlDataBase.GetDataTable(Sql);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    this.gridControl1.DataSource = dataTable;
                }
                Sql = string.Format(@"SELECT sortNo
                    ,temperature
                    FROM output_temperature{1}
                    WHERE batchId = '{0}'
                    ORDER BY sortNo"
                    , id, Separattion);
                DataTable dataTable1 = base.class_MySqlDataBase.GetDataTable(Sql);
                if (dataTable1 != null && dataTable1.Rows.Count > 0)
                {
                    this.labelControl9.Text = dataTable1.Rows[0]["temperature"].ToString();
                    if (dataTable.Rows.Count > 1)
                        this.labelControl10.Text = dataTable1.Rows[1]["temperature"].ToString();
                }
                dataTable1.Dispose();
            }

        }
        protected override void DisplayComponent(string id)
        {
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void Form_ResultCal_Load(object sender, EventArgs e)
        {
            Ini();
        }
    }
}
